package main.java;

public class Queue implements IQueue {
	private Element first;
	private Element last;
	private int size;
	static final int QUEUE_EMPTY = 0;
	
	public Queue(){
		this.first = null;
		this.last = null;
		this.size = 0;
	}

	public boolean isEmpty(){
		return (this.size == QUEUE_EMPTY);
	}
	
	public int size(){
		return this.size;
	}
	
	public void add(Object item){
		Element newElement = new Element(item);
		if (this.isEmpty()){
			this.first = newElement;
			this.last = newElement;
		}
		else{
			this.last.setNext(newElement);
			this.last = newElement;
		}
		this.size ++;
	}

	public Object top(){
		this.checkEmptyQueue();
		return  this.first.getValue();
	}
	
	public void remove(){
		this.checkEmptyQueue();
		this.first = this.first.getNext();
		this.size--;
	}
	
	private void checkEmptyQueue()throws AssertionError{
		if(this.isEmpty()){
			throw new AssertionError();
		}
	}
}
